﻿using Microsoft.EntityFrameworkCore;
using mozhi.smarterp.AuthorCenter.EntityFrameworkCore;
using mozhi.smarterp.AuthorCenter.Users.Repositories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore;

namespace mozhi.smarterp.AuthorCenter.Users
{
    public class UserDataPermissionRepository : EfCoreRepository<AuthorCenterDbContext, UserDataPermission, Guid>, IUserDataPermissionRepository
    {
        public UserDataPermissionRepository(IDbContextProvider<AuthorCenterDbContext> dbContextProvider) : base(dbContextProvider)
        {
        }

        public async Task<UserDataPermission> FindAsync(Guid userId, CancellationToken cancellationToken = default)
        {
            var dbContext = await GetDbContextAsync();

            var entity = await dbContext.Set<UserDataPermission>().AsNoTracking().FirstOrDefaultAsync(x => x.UserId == userId);

            return entity;
        }
    }
}
